package com.flmes.base.util;

import lombok.experimental.UtilityClass;
import org.mindrot.jbcrypt.BCrypt;

/**
 * @Author: flmes
 * @Date: 2024/9/27 19:19
 */
@UtilityClass
public class BcryptPasswordUtil {

    /**
     * 生成散列后密码
     * @param rawPassword
     * @return
     */
    public String encodePassword(String rawPassword) {
        return BCrypt.hashpw(rawPassword, BCrypt.gensalt(10));
    }

    /**
     * 校验密码
     * @param rawPassword
     * @param encodedPassword
     * @return
     */
    public boolean checkPw(String rawPassword, String encodedPassword) {
        return BCrypt.checkpw(rawPassword, encodedPassword);
    }

}
